#include <stdio.h>
#include <stdlib.h>
#include <math.h>


//#define DEBUG

#ifdef DEBUG
    #define ASSERT(cond)                                                                        \
    if (!(cond))                                                                                \
    {                                                                                           \
        printf("The state is wrong: %s, file: %s, line: %d\n", #cond, __FILE__, __LINE__);      \
        abort();                                                                                \
    }

#else
    #define ASSERT(cond)
#endif //DEBUG


//#define _EJC

#ifdef  _EJC
    #define OUT if (0)
#else
    #define OUT
#endif // _EJC


/**
    Normalize - puts a natural number n into a form ( b * sqrt (a) )

    @param          num         the number
    @param[out]     factor      it's b in the discription
    @param[out]     in_sqrt     it's a in the discription

    @par            b is as great as possible
**/

void Normalize (long n, long* in_sqrt, long* factor);


int main ()
{
    long n = 0, in_sqrt = 0, factor = 0;

    OUT printf ("# This program puts a natural number n\n"
                "  into a form ( b * sqrt (a) ) (b is as great as possible)\n"
                "# The developer:   Yura Gorishniy      <strausmg@gmail.com>\n"
                "# Version 1.00\n"
                "# File: %s\n"
                "# The compilation time: %s, %s\n\n", strrchr (__FILE__, '\\'), __DATE__, __TIME__);

    OUT printf ("# Enter a natural number (type it and press ENTER)\n\n");

    if (scanf ("%ld", &n) != 1) {printf ("Incorrect input, try again"); return -1;}

    Normalize (n, &in_sqrt, &factor);

    OUT printf ("\n" "%ld = ", n);
    printf ("%ld ", factor);
    OUT printf ("* sqrt (");
    printf ("%ld", in_sqrt);
    OUT printf (")");

return 0;
}


void Normalize (long num, long* in_sqrt, long* factor)
{
    ASSERT (factor);
    ASSERT (in_sqrt);
    ASSERT (in_sqrt != factor);

    *in_sqrt = -1;

    long divisor = 0;
    long sqrt_num = floor (sqrt (num));
    long num_new = num / 2;

    for (divisor = 1; divisor <= num_new; ++divisor)
    {
        if (num % divisor == 0)
        {
            double sqrtnd = sqrt (num / divisor);
            if (sqrtnd == floor (sqrtnd))
            {
                *in_sqrt = divisor;
                *factor = sqrtnd;
                break;
            }
        }
    }
    if (*in_sqrt == -1) {*in_sqrt = num; *factor = 1;}

return;
}
